﻿using BCCommon; 
using BCDto.Common.ErrorMessage; 
using BCDto.TMS.TransferStation; 
using BCService.TMS.TransferStation;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.TransferStation
{
    /// <summary>
    /// 仓库中转站接口
    /// </summary> 
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class TransferStationController : ManagementBaseController
    {
        #region var
        private ITransferStationService transferStationService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public TransferStationController(ITransferStationService transferStationService)
        {
            this.transferStationService = transferStationService;
        }
        #endregion

        #region POST 添加 添加新仓库中转站纪录 仓库中转站数据模型

        [Log("添加新仓库中转站纪录")]
        [HttpPost]
        [ProducesResponseType(typeof(TransferStationRequestDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 401)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Post([FromBody] TransferStationRequestDto dto)
        {
            var a = transferStationService.Add(dto, this.Admin);
            return Ok(a);
        }

        #endregion

        #region PUT 修改 修改仓库中转站纪录  仓库中转站数据模型

        [Log("修改仓库中转站纪录")]
        [HttpPut]
        [ProducesResponseType(typeof(TransferStationDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 401)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Put([FromBody] TransferStationDto dto)
        {
            var a = Ok(transferStationService.Update(dto, this.Admin));
            return a;
        }
        #endregion

        #region 删除 删除仓库中转站纪录 仓库中转站ID

        [Log("删除仓库中转站纪录")]
        [HttpDelete("{transfer_station}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Delete([FromQuery(Name = "transfer_station")] long transferStationId)
        {
            transferStationService.Delete(transferStationId);
            return NoContent();
        }
        #endregion

        #region GetByID   获取一条仓库中转站纪录  仓库中转站ID

        [HttpGet("{transfer_station}")]
        [ProducesResponseType(typeof(TransferStationDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 401)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Get([FromRoute(Name = "transfer_station")] long transferStationId)
        {
            return (Ok(transferStationService.GetById(transferStationId)));

        }
        #endregion

        #region Query 查询仓库中转站

        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<TransferStationDto>), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Query([FromQuery(Name = "index")] int? pageIndex = 1, [FromQuery(Name = "size")] int? pageSize = 10)
        {
            var a = Ok(transferStationService.GetList(pageIndex.Value, pageSize.Value));
            return a;
        }
        #endregion
    }
}